#表单model add by Luxh
common_util = require('../services/common_util')
config = require('../config')
Schema = config.Schema
mongoose = config.mongoose

FormSchema = new Schema({
  form_code:
    type:String
    index:true
  form_name:String
  form_desc:String
  updated_at : Date
  fields:[
    {
      xtype:String,
      field_label:String,
      name:String,
      allow_blank:Boolean,
      order:Number,
      colspan:Number,
      width:Number,
      height:Number,
      data_type:{type:String,default:'String'},
      data_format:String,
      read_only:Boolean,
      display_field:String,
      value_field:String,
      use_url:Boolean,
      url:String,
      items:String
      cascade_field2 : String,
      cascade_label2 : String,
      url2 : String,
      items2 : String,
      cascade_field3 : String,
      cascade_label3 : String,
      url3 : String,
      items3 : String
    }
  ]
  search_fields:[{name:String,is_like:Boolean}]
})

FormSchema.methods.add = (req,cb) ->
  this.form_code = common_util.trim(req.param("form_code"))
  this.form_name = req.param('form_name')
  this.form_desc = req.param('form_desc')
  this.updated_at = new Date
  this.save cb


exports.Form = mongoose.model 'form',FormSchema
